package org.example.code.test2024.eight_mouth;

import java.util.*;

public class test0803 {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        int k = 0, max = Integer.MIN_VALUE;
        while (k < n) {
            int count = in.nextInt();
            a[k] = count;
            k++;
        }
        for (int i = 0; i < n; i++) {
            if (i + 1 < n) {
                max = Math.max(a[i] * a[i + 1], max);
                if (i - 1 >= 0) {
                    max = Math.max(a[i - 1] * a[i + 1], max);
                }
                if (i + 2 < n) {
                    max = Math.max(a[i] * a[i + 2], max);
                }
            }
        }
        System.out.println(max);
    }

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hashMap.containsKey(target - nums[i])) {
                return new int[]{i, hashMap.get(target - nums[i])};
            }
            hashMap.put(nums[i], i);
        }
        return new int[0];
    }

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> hashMap = new HashMap<>();
        for (String a : strs) {
            char[] charArray = a.toCharArray();
            Arrays.sort(charArray);
            String str = new String(charArray);
            if (hashMap.containsKey(str)) {
                hashMap.get(str).add(a);
                continue;
            }
            List<String> list = new ArrayList<>();
            list.add(a);
            hashMap.put(str, list);
        }
        List<List<String>> list = new ArrayList<>();
        for (String a : hashMap.keySet()) {
            list.add(hashMap.get(a));
        }
        return list;
    }

    public int longestConsecutive(int[] nums) {
        Set<Integer> hashSet = new HashSet<>();
        for (Integer a : nums) {
            hashSet.add(a);
        }
        int max = 0;
        for (Integer a : hashSet) {
            if (!hashSet.contains(a - 1)) {
                int len = 1;
                while (hashSet.contains(a + 1)) {
                    len++;
                    a++;
                }
                max = Math.max(max, len);
            }
        }
        return max;
    }

    public void moveZeroes(int[] nums) {
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                int t = nums[i];
                nums[i] = nums[j];
                nums[j++] = t;
            }
        }
    }

    public int maxArea(int[] height) {
        int l = 0, r = height.length - 1;
        int max = 0;
        while (l < r) {
            int area = Math.min(height[l], height[r]) * (r - l);
            max = Math.max(max, area);
            if (height[l] > height[r]) {
                r--;
            } else {
                l++;
            }
        }
        return max;
    }


    public List<List<Integer>> threeSum(int[] nums) {
        int n = nums.length;
        Arrays.sort(nums);
        List<List<Integer>> integers = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (i != 0 && nums[i] == nums[i - 1]) {
                continue;
            }
            int t = -nums[i];
            int third = n - 1;
            for (int j = i + 1; j < n; j++) {
                if (j > i && nums[j] == nums[j - 1]) {
                    continue;
                }
                while (j > third && nums[j] + nums[third] > t) {
                    third--;
                }
                if (third == j) {
                    break;
                }
                if (nums[j] + nums[third] == t) {
                    ArrayList<Integer> list = new ArrayList<>();
                    list.add(nums[i]);
                    list.add(nums[j]);
                    list.add(nums[third]);
                    integers.add(list);
                }
            }
        }
        return integers;
    }

    //    0,1,0,2,1,0,1,3,2,1,2,1
    public int trap(int[] height) {
        int n = height.length,sum=0;
        if(n==0)
            return 0;
        int []maxL = new int[n];
        int []maxR = new int[n];
        for(int i=0;i<n;i++){
            if(i==0){
                maxL[i]=height[i];
                continue;
            }
            maxL[i] = Math.max(height[i],maxL[i-1]);
        }
        for(int i=n-1;i>-1;i--){
            if(i==n-1){
                maxR[i] = height[i];
                continue;
            }
            maxR[i] = Math.max(maxR[i+1],height[i]);
        }
        for(int i=0;i<n;i++){
            sum=sum+Math.min(maxR[i],maxL[i])-height[i];
        }
        return sum;
    }

    public int lengthOfLongestSubstring(String s) {
        int maxLen = 0;
        char[] array = s.toCharArray();
        LinkedList<Character> characterLinkedList = new LinkedList<>();
        for(int i=0;i<array.length;i++){
            if(characterLinkedList.contains(array[i])){
                maxLen = Math.max(maxLen,characterLinkedList.size());
                while(characterLinkedList.contains(array[i])){
                    characterLinkedList.removeFirst();
                }
                characterLinkedList.add(array[i]);
            }else{
                characterLinkedList.addLast(array[i]);
            }
        }
        return Math.max(maxLen,characterLinkedList.size());
    }

    public List<Integer> findAnagrams(String s, String p) {
        char[] chars = s.toCharArray();
        char[] pCharArray = p.toCharArray();
        Arrays.sort(pCharArray);
        String tar = new String(pCharArray);
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<chars.length;i++){
            if(i+pCharArray.length> chars.length-1)
                break;
            String str = s.substring(i,i+pCharArray.length);
            char[] charArray = str.toCharArray();
            Arrays.sort(charArray);
            String sTwo = new String(charArray);
            if(sTwo.equals(tar)){
                list.add(i);
            }
        }
        return list;
    }

    public int[] maxSlidingWindow(int[] nums, int k) {
        LinkedList<Integer> list = new LinkedList<>();
        LinkedList<Integer> maxList = new LinkedList<>();
        list.add(nums[0]);
        for(int i=1;i<k;i++){
            if(nums[i]<list.getFirst()){
                list.addLast(nums[i]);
            }else{
                list.addFirst(nums[i]);
            }
        }
        maxList.add(list.getFirst());
        for(int i=k;i<nums.length;i++){
            int x = nums[i-k];
            System.out.println(list.contains(x)+"   "+(i-k));
           list.remove((Integer) i-k);
           if(nums[i]<list.getFirst()){
               list.addLast(nums[i]);
           }else{
               list.addFirst(nums[i]);
           }
            maxList.add(list.getFirst());
        }
        int []ans = new int[maxList.size()];
        for(int i=0;i<maxList.size();i++){
            ans[i] = maxList.get(i);
        }
        return ans;
    }

    public int maxSubArray(int[] nums) {
        int []dp = new int[nums.length];
        int max = Integer.MIN_VALUE;
        dp[0] = nums[0]>0?nums[0]:0;
        for(int i=1;i<nums.length;i++){
            dp[i] = Math.max(dp[i-1]+nums[i],nums[i]);
            max = Math.max(max,dp[i]);
        }
        return max;
    }
    public int[][] merge(int[][] intervals) {
        if(intervals.length==0){
            return new int[0][2];
        }
        Arrays.sort(intervals, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0]-o2[0];
            }
        });
        List<int[]> list = new ArrayList<>();
        for(int i=0;i<intervals.length;i++){
            int a1 = intervals[i][0];
            int a2 = intervals[i][1];
            int n = list.size();
            if(list.isEmpty()||list.get(n-1)[0]>a1){
                list.add(intervals[i]);
            }else{
                list.get(n-1)[1] = Math.max(list.get(n-1)[1],a2);
            }
        }
        return list.toArray(new int[list.size()][]);
    }

    public void rotate(int[] nums, int k) {
        int t = nums.length-k;
        int []arr = new int[nums.length];
        for(int i=0;i<nums.length;i++){
            if(t==nums.length){
                t=0;
            }
            arr[i] = nums[t];
            System.out.println(arr[i]+"  "+t);
        }
        for(int i=0;i<nums.length;i++){
            arr[i] = nums[i];
        }
    }

    public int[] productExceptSelf(int[] nums) {
        int []resultL = new int[nums.length];
        int []resultR = new int[nums.length];
        resultL[0]=1;
        resultR[resultL.length-1] = 1;
        for(int i=0;i<nums.length-1;i++){
            resultL[i+1] = resultL[i]*nums[i];
            System.out.println(resultL[i]);
        }
        for(int i=nums.length-1;i>0;i--){
            resultR[i-1] = resultL[i]*nums[i];
            System.out.println(resultR[i]);
        }
        for(int i=0;i<resultL.length;i++){
            nums[i] = resultL[i]*resultR[i];
        }
        return nums;
    }

    public int firstMissingPositive(int[] nums) {
        Arrays.sort(nums);
        int min = 1;
        for(int i=0;i<nums.length;i++){
            if(min<nums[i]&&nums[i]!=0){
                return min;
            }
            min = nums[i];
        }
        return min;
    }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode pB = headB;
        ListNode pA = headA;
        while(pA!=null){
            while(pB!=null){
                if(pA==pB){
                    return pA;
                }
                pB = pB.next;
            }
            pB = headB;
            pA = pA.next;
        }
        return null;
    }
}